package com.wyl.asynctask.controller;

import com.wyl.asynctask.entity.GoodsInfo;
import com.wyl.asynctask.service.AsyncTaskManager;
import com.wyl.asynctask.vo.AsyncTaskInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: wyl
 * @date: 2021/10/12
 * @des: 商品异步入库服务
 */
@Slf4j
@RestController
@RequestMapping("/async-goods")
public class AsyncGoodsController {

    @Resource
    private AsyncTaskManager asyncTaskManager;

    /**
     * 导入商品进入到商品表
     *
     * @param goodsInfos
     * @return
     */
    @PostMapping("/import-goods")
    public AsyncTaskInfo importGoods(@RequestBody List<GoodsInfo> goodsInfos) {
        return asyncTaskManager.submit(goodsInfos);
    }

    /**
     * 查询异步任务的执行状态
     *
     * @param taskId
     * @return
     */
    @GetMapping("/task-info")
    public AsyncTaskInfo getTaskInfo(@RequestParam String taskId) {
        return asyncTaskManager.getTaskInfo(taskId);
    }

}
